jQuery(document).ready(function() {

	var baseurlsummary = baseurl + "summary/";
	
	if (/summary/.test(self.location.href)){
	
	var mobtel = getCookie("fb_mobtel");
	jQuery.getJSON(baseurlsummary+"retrieveUserProfileToDB/"+mobtel,{ajax:'true'},function(j){
       for(var i=0;i<j.length;i++){

       }
	});
	
	}

	jQuery('#agree').click(function(){
	
	   if(document.getElementById("agree").checked == true)
	      jQuery('#confirm').removeClass("disable");
	   else
		  jQuery('#confirm').addClass("disable");
	
	});
	
	jQuery('#changedevice').click(function(){
		document.cookie="fb_mode=" + "edit" + "; path=/";
		window.location=baseurl + "gallery";
		return false;
	});
	
	jQuery('#changemobtel').click(function(){
		document.cookie="fb_mode=" + "edit" + "; path=/";
		jQuery('#mobile_number2').val("");
		jQuery('#verif_code2').val("");
		jQuery('#verificationCode2').hide();
		jQuery('.dialog_overlay').fadeIn();
		jQuery('.modalStyle').css({"width":"575px","top":"555px"});
		jQuery('#modalmobtel').fadeIn();
		jQuery('#modalmobtel').css({"z-index":"102","position":"fixed","top":"-28%","left":"28%"});
		return false;
	});
	
	jQuery('#changeuserprofile').click(function(){
		document.cookie="fb_mode=" + "edit" + "; path=/";
		window.location=baseurl + "userprofile";
		return false;
	});
	
	jQuery('#changestore').click(function(){
		document.cookie="fb_mode=" + "edit" + "; path=/";
		window.location=baseurl + "globestore";
		return false;
	});
	
	jQuery('.closeIcon').click(function(){
		jQuery('.dialog_overlay').fadeOut();
		jQuery('#modalmobtel').fadeOut();
		return false;
	});
	
	//Start of Code Change Mobile Number
	
	$("#mobile_number2").keypress(function (e) {
		if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
		return false;
		}
	});	

	$("#verif_code2").keypress(function (e) {
		if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
		return false;
		}
	});	

	jQuery("#submit_mobtel2").click(function(){
	
	jQuery(".error1").css("margin-top","50px");
	jQuery(".error2").css("margin-top","50px");
	
		mobtel=jQuery("#mobile_number2").val();
		if(mobtel.length!=11) {
			jQuery("#submit_mobtel2").text("Send Code");
			jQuery(".error1").show();
			jQuery(".error2").hide();
			jQuery("#verificationCode2").hide();
		} else {
			jQuery("#prepaidNumber2 .errorBox").hide();
			
			jQuery.getJSON(baseurl + "prepaid/verifynumber3/" + mobtel,{ajax: 'true'}, function(j){
				if(j.status==0) {
					jQuery("#submit_mobtel2").text("Resend Code");
					jQuery(".error1").hide();
					jQuery(".error2").hide();
					jQuery("#verificationCode2").show();
				} else if (j.status==-2){
				    jQuery(".error1").hide();
					jQuery(".error2").show();
					jQuery("#verificationCode").hide();
				} else {
					jQuery(".error1").show();
					jQuery("#verificationCode").hide();
				}		
			});
		}
	});
	
	jQuery("#validate_verif_code2").click(function() {
	
	jQuery(".errorBox2").css("margin-top","50px");
	
		vcode=jQuery("#verif_code2").val();
		if(vcode.length==6) {
			jQuery("#verificationCode2 .errorBox2").hide();
			
			jQuery.getJSON(baseurl + "prepaid/verifycode/" + vcode,{ajax: 'true'}, function(j){
				if(j.status==0) {
					jQuery("#verificationCode2 .errorBox2").hide();
					jQuery("#savechanges").removeClass("disable");
					jQuery("#savechanges").removeAttr("disabled", false);
				} else {
					jQuery("#verificationCode2 .errorBox2").show();
				}	
			});
		} else {
			jQuery("#verificationCode2 .errorBox2").show();
		}
	});
	
	jQuery("#savechanges").click(function() {
	   if (!jQuery("#savechanges").hasClass("disable")) {
		document.cookie="fb_oldmobtel=" + jQuery("#sum-mobtel").text() + "; path=/";
		var mobile_number2 = jQuery("#mobile_number2").val();
		document.cookie="fb_mobtel=" + mobile_number2 + "; path=/";
		jQuery("#sum-mobtel").text(mobile_number2);
		
			jQuery.getJSON(baseurl + "prepaid/savenumber/",{ajax: 'true'}, function(j){
				if(j.status==0) {
				    jQuery('.dialog_overlay').fadeOut();
				    jQuery('#modalmobtel').fadeOut();
				} else {
					jQuery(".error1").text(j.error);
					jQuery(".error1").show();
				}		
			});
       }
	});
	
	//End of Code Change Mobile Number
	
});


   function getCookie(fb_cname) {
	var name = cname + "=";
	var ca = document.cookie.split(';');
	for(var i=0; i<ca.length; i++) 
	{
	var c = ca[i].replace(/\s/g, "");
	if (c.indexOf(name)==0) return c.substring(name.length,c.length);
	}
	return "";
   }